﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Game.model;

namespace Game.ai
{
    public class SummonAI:PlayableAI
{
	/**
	 * Constructor for SummonAI.
	 * @param actor Summon
	 */
	public SummonAI(Summon actor):base(actor)
	{
		//super(actor);
	}
	
	/**
	 * Method thinkActive.
	 */
	
	protected override void thinkActive()
	{
		Summon actor = getActor();
		clearNextAction();
		if (actor.isDepressed())
		{
			setAttackTarget(actor.getPlayer());
			changeIntention(CtrlIntention.AI_INTENTION_ATTACK, actor.getPlayer(), null);
			thinkAttack(true);
		}
		else if (actor.isFollowMode())
		{
			changeIntention(CtrlIntention.AI_INTENTION_FOLLOW, actor.getPlayer(), Config.FOLLOW_RANGE);
			thinkFollow();
		}
		else if (!actor.isFollowMode() && getIntention() == AI_INTENTION_ACTIVE)
		{
			actor.setFollowMode(true);
		}
		base.thinkActive();
	}
	
	/**
	 * Method thinkAttack.
	 * @param checkRange boolean
	 */
	
	protected override void thinkAttack(bool checkRange)
	{
		Summon actor = getActor();
		if (actor.isDepressed())
		{
			setAttackTarget(actor.getPlayer());
		}
		base.thinkAttack(checkRange);
	}
	
	/**
	 * Method onEvtAttacked.
	 * @param attacker Creature
	 * @param damage int
	 */
	
	protected override void onEvtAttacked(Creature attacker, int damage)
	{
		Summon actor = getActor();
		if ((attacker != null) && actor.getPlayer().isDead() && !actor.isDepressed())
		{
			Attack(attacker, false, false);
		}
		if (actor.getPlayer().isDebug())
			actor.getPlayer().sendMessage("SummonAI onEvtAttacked isDefendMode:" + actor.isDefendMode() + " isDepressed:" + actor.isDepressed() + " " + attacker.getName());
		if ((attacker != null) && actor.isDefendMode() && !actor.isDepressed())
		{
			Attack(attacker, false, false);
		}
		base.onEvtAttacked(attacker, damage);
	}
	
	/**
	 * Method getActor.
	 * @return Summon
	 */
	
	public override Summon getActor()
	{
		return (Summon) base.getActor();
	}
}
}
